﻿/****************************** Module Header ******************************\
 * Module Name:  MouseEventHelper.cs
 * Module Version:  1.0.0 (2013-7-9)
 * Copyright (c) AnyEB.Com (14507247@qq.com)
 * 
 * This class is used to operate the file or the directory. It supplies some
 * public method to move a folder,copy a folder,replace a file and so on.
 * 
 * This source is subject to the GPL License.
 * See http://www.gnu.org/licenses/gpl.html.
 * All other rights reserved.
 * 
 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 
 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
\***************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UCL.Forms.WinAPI
{
    /// <summary>
    /// 程序中我们直接调用mouse_event函数就可以了 
    /// <para>mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, 500, 500, 0, 0); </para>
    /// <para></para>
    /// <para>1、这里是鼠标左键按下和松开两个事件的组合即一次单击： </para>
    /// <para>mouse_event (MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 ) </para>
    /// <para></para>
    /// <para>2、模拟鼠标右键单击事件： </para>
    /// <para>mouse_event (MOUSEEVENTF_RIGHTDOWN | MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0 )</para> 
    /// <para></para>
    /// <para>3、两次连续的鼠标左键单击事件 构成一次鼠标双击事件： </para>
    /// <para>mouse_event (MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 ) </para>
    /// <para>mouse_event (MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0 ) </para>
    /// <para></para>
    /// <para>4、使用绝对坐标 </para>
    /// <para>MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, 500, 500, 0, 0 </para>
    /// <para></para>
    /// <para>需要说明的是，如果没有使用MOUSEEVENTF_ABSOLUTE，函数默认的是相对于鼠标当前位置的点，如果dx，和dy，用0，0表示，这函数认为是当前鼠标所在的点。</para>
    /// <para>5、直接设定绝对坐标并单击</para>
    /// <para>mouse_event(MOUSEEVENTF_LEFTDOWN, X * 65536 / 1024, Y * 65536 / 768, 0, 0); </para>
    /// <para>mouse_event(MOUSEEVENTF_LEFTUP, X * 65536 / 1024, Y * 65536 / 768, 0, 0); </para>
    /// <para>其中X，Y分别是你要点击的点的横坐标和纵坐标 </para>
    /// </summary>
    public class MouseEventHelper
    {

        [System.Runtime.InteropServices.DllImport("user32")]
        public static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);

        /// <summary>
        /// 定义了辅助键的名称（将数字转变为字符以便于记忆，也可去除此枚举而直接使用数值）
        /// </summary>
        [Flags()]
        public enum KeyModifiers
        {
            MOUSEEVENTF_MOVE = 0x0001,        // 移动鼠标 
            MOUSEEVENTF_LEFTDOWN = 0x0002,    // 模拟鼠标左键按下 
            MOUSEEVENTF_LEFTUP = 0x0004,      // 模拟鼠标左键抬起 
            MOUSEEVENTF_RIGHTDOWN = 0x0008,   // 模拟鼠标右键按下 
            MOUSEEVENTF_RIGHTUP = 0x0010,      // 模拟鼠标右键抬起 
            MOUSEEVENTF_MIDDLEDOWN = 0x0020,  // 模拟鼠标中键按下 
            MOUSEEVENTF_MIDDLEUP = 0x0040,    // 模拟鼠标中键抬起 
            MOUSEEVENTF_ABSOLUTE = 0x8000,    // 标示是否采用绝对坐标 
        }
    }
}
